<!DOCTYPE HTML>
<html xmlns=" http://www.w3.org/1999/xhtml">
    <head>


        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>showStorage</title>
        <script type="text/javascript">
        	//C:\Users\your-account-name\AppData\Local\Mozilla\Firefox\Profiles\
//C:\Users\XXX\AppData\Local\Microsoft\Internet Explorer\DOMStore
			
			if(window.addEventListener){
			 window.addEventListener("storage",handle_storage,false);
			}else if(window.attachEvent){
			 window.attachEvent("onstorage",handle_storage);
			}
			function handle_storage(e){
				alert(0);
			 if(!e){e=window.event;}
			 //showStorage();
			   console.log(e.key + "'s value is changed from '" +
                e.oldValue +
                "' to '" +
                e.newValue +
                "' by " +
                e.url);
			}


            
            
            
            
            localStorage.setItem("name", '人们');
            console = {
                log: function(string){
                    var logItem = document.getElementById("log");
                    var temp = logItem.innerHTML;
                    logItem.innerHTML = temp + "<br>" + string;
                    
                }
                
            }
            function supports_html5_storage(){
                try {
                    return 'localStorage' in window && (window['localStorage'] != null);
                } 
                catch (e) {
                    return false;
                }
            }
            
            function showStorage(){
                if (supports_html5_storage()) {
                    for (var i = 0; i < localStorage.length; i++) {
                        var key = localStorage.key(i);
                        console.log(key + ":" + localStorage[key]);
                    }
                }
            }
            
            	 var UserData = {
        userData : null,
        name : location.hostname,
        //this.name = "css88.com";

        init:function(){
			alert(location.hostname);
            if (!UserData.userData) {
                try {
                    UserData.userData = document.createElement('INPUT');
                    UserData.userData.type = "hidden";
                    UserData.userData.style.display = "none";
                    UserData.userData.addBehavior ("#default#userData");
                    document.body.appendChild(UserData.userData);
                    var expires = new Date();
                    expires.setDate(expires.getDate()+365);
                    UserData.userData.expires = expires.toUTCString();
                } catch(e) {
                    return false;
                }
            }
            return true;
        },

        setItem : function(key, value) {

            if(UserData.init()){
                UserData.userData.load(UserData.name);
                UserData.userData.setAttribute(key, value);
                UserData.userData.save(UserData.name);
            }
        },

        getItem : function(key) {
            if(UserData.init()){
            UserData.userData.load(UserData.name);
            return UserData.userData.getAttribute(key)
            }
        },

        remove : function(key) {
            if(UserData.init()){
            UserData.userData.load(UserData.name);
            UserData.userData.removeAttribute(key);
            UserData.userData.save(UserData.name);
            }

        },
		   // 检查userdata文件是否存在 f-文件名
	    exist : function(f){
	        return UserData.userData.load(UserData.name) != null;
	    }
    };
        </script>
    </head>
    <body>
        <p>
            This is a paragraph.
        </p>
        <button onclick="showStorage()">
            showStorage()
        </button>
		<button onclick="alert(UserData.getItem('age'))">
           UserData.getItem()
        </button>
        <br>
        <div id="log">
        </div>
    </body>
</html>
